package com.blu.service.impl;

import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.blu.entity.Account;
import com.blu.mapper.AccountMapper;
import com.blu.service.AccountService;

@Service
public class AccountServiceImpl implements AccountService{

	@Autowired
	private AccountMapper mapper;
	
	@Override
	public Account findByUsername(String name) {
		QueryWrapper<Account> wrapper = new QueryWrapper<Account>();
		wrapper.eq("username", name);
		Account account = mapper.selectOne(wrapper);
		return account;
	}

	@Override
	public void createAccount(Account account) {
		String salt = new SecureRandomNumberGenerator().nextBytes().toString();
		//对密码加密
		String password= new SimpleHash("md5",account.getPassword(),salt,2).toString();
		account.setPassword(password);
		account.setSalt(salt);
		mapper.insert(account);
	}

}
